package edu.chinasoft.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.annotation.WebServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import edu.chinasoft.domain.Role;
import edu.chinasoft.service.RoleService;

/**
 *
 * @author mhao
 * @date 2020年2月12日:下午3:56:48
 * @version V1.0
 * @Description: 
*/
@WebServlet(name = "myDelectRoleServlet", value = "/servlet/delectroleservlet")
public class DelectRoleServlet extends HttpServlet {
	private static Logger logger = LoggerFactory.getLogger(DelectRoleServlet.class);
	private RoleService roleService;
	/**
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.info(" DelectRoleServlet >doGet start.......");
		response.setContentType("text/html;charset=utf-8");
		response.setCharacterEncoding("utf-8");
		WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
		RoleService roleServiceImp = wac.getBean("roleService", RoleService.class);
		this.roleService=roleServiceImp;
		//获取当前商品的id
		String num = request.getParameter("id");
		int id = Integer.parseInt(num);
		Role role = new Role();
		role.setRoleId(id);
		//调用service的方法删除该商品
		boolean result = roleService.deleteRoleByRoleId(role);
		if(result) {
			//删除成功
			response.sendRedirect(""+request.getContextPath()+"/servlet/showroleservlet");
		}else {
			//删除失败
			response.sendRedirect(""+request.getContextPath()+"/deleteroleerror.jsp");
		}
		logger.info(" DelectRoleServlet >doGet end.......");
	}

	/**
	 *
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.info(" DelectRoleServlet >doPost start.......");
		this.doGet(request, response);
		logger.info(" DelectRoleServlet >doPost end.......");
	}

}